package pool 
{
	import flash.utils.*;
	/**
	 * ...
	 * @author gcxk721
	 */
	public class ObjectPool 
	{
		
		private static var pools : Dictionary = new Dictionary();

        public function ObjectPool()
        {
            
        }

        private static function getPool(cls : Class) : Array
        {
			if (cls in pools)
			{
				return pools[cls];
			}
			var array : Array = new Array();
			pools[cls] = new Array();
			return array;
        }
		
        public static function getObject(cls : Class) : Object
        {
            var array : Array = getPool(cls);
            if (array.length > 0)
            {
                return array.pop();
            }
            //return construct(cls, args);
			return new cls();
        }

        public static function disposeObject(param : *, cls : Class = null) : void
        {
            var clsName:String = null;
            if (cls == null)
            {
                clsName = getQualifiedClassName(param);
                cls = getDefinitionByName(clsName) as Class;
            }
            var array : Array = getPool(cls);
            array.push(param);
        }
		
	}

}